package com.mt.operation.service.model;

import java.util.List;
import java.util.Map;

import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import com.github.pagehelper.PageHelper;
import com.mt.common.PagerInfo;
import com.mt.common.ServiceResult;
import com.mt.operation.entity.RecommendFloorCourseEntity;
import com.mt.operation.mapper.RecommendFloorCoursesEntityMapper;

@Component
public class RecommendFloorCourseServiceModel {

    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(RecommendFloorCourseServiceModel.class);

    @Autowired
    private RecommendFloorCoursesEntityMapper recommendFloorCoursesEntityMapper;

    public ServiceResult<List<RecommendFloorCourseEntity>> selectList(Map<String, Object> params, PagerInfo<?> pagerInfo) {
        Assert
            .notNull(this.recommendFloorCoursesEntityMapper, "Property 'recommendFloorCoursesEntityMapper' is required.");
        ServiceResult<List<RecommendFloorCourseEntity>> result = new ServiceResult<List<RecommendFloorCourseEntity>>();
        try {
            if (pagerInfo != null) {
                PageHelper.startPage(pagerInfo.getPageIndex(), pagerInfo.getPageSize());
            }
            result.setResult(this.recommendFloorCoursesEntityMapper.selectList(params));
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[RecommendFloorCoursesServiceModel][selectList]：query selectList occur exception", e);
        }
        return result;
    }

    public ServiceResult<RecommendFloorCourseEntity> selectInfo(Map<String, Object> params) {
        Assert
            .notNull(this.recommendFloorCoursesEntityMapper, "Property 'recommendFloorCoursesEntityMapper' is required.");
        ServiceResult<RecommendFloorCourseEntity> result = new ServiceResult<RecommendFloorCourseEntity>();
        try {
            result.setResult(this.recommendFloorCoursesEntityMapper.selectByPrimaryKey(params));
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[RecommendFloorCoursesServiceModel][selectInfo]：query selectInfo occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> insert(RecommendFloorCourseEntity recommendFloorCoursesEntity) {
        Assert
            .notNull(this.recommendFloorCoursesEntityMapper, "Property 'recommendFloorCoursesEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        int save = 0;
        try {
            List<RecommendFloorCourseEntity> recommendFloorCourseList = recommendFloorCoursesEntity.getRecommendFloorCourseList();
            if (recommendFloorCourseList != null && recommendFloorCourseList.size() > 0) {
                save = this.recommendFloorCoursesEntityMapper.insertList(recommendFloorCourseList);
            } else {
                save = this.recommendFloorCoursesEntityMapper.insert(recommendFloorCoursesEntity);
            }
            if (save > 0) {
                result.setResult(save);
            }
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[RecommendFloorCoursesServiceModel][insert]：query insert occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> insertList(List<RecommendFloorCourseEntity> list) {
        Assert
            .notNull(this.recommendFloorCoursesEntityMapper, "Property 'recommendFloorCoursesEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.recommendFloorCoursesEntityMapper.insertList(list);
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[RecommendFloorCoursesServiceModel][insertList]：query insert occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> updateByPrimaryKeySelective(RecommendFloorCourseEntity recommendFloorCoursesEntity) {
        Assert
            .notNull(this.recommendFloorCoursesEntityMapper, "Property 'recommendFloorCoursesEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.recommendFloorCoursesEntityMapper.updateByPrimaryKeySelective(recommendFloorCoursesEntity);
            if (save > 0) {
                id = recommendFloorCoursesEntity.getRecommendCourseGoodsId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[RecommendFloorCoursesServiceModel][updateByPrimaryKeySelective]:query update occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> deleteByPrimaryKey(Integer recommendCourseGoodsId) {
        Assert
            .notNull(this.recommendFloorCoursesEntityMapper, "Property 'recommendFloorCoursesEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int save = 0;
        try {
            save = this.recommendFloorCoursesEntityMapper.deleteByPrimaryKey(recommendCourseGoodsId);
            result.setResult(save);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[RecommendFloorCoursesServiceModel][deleteByPrimaryKey]:query update occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> delete(Integer recommendCourseGoodsId) {
        Assert
            .notNull(this.recommendFloorCoursesEntityMapper, "Property 'recommendFloorCoursesEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int save = 0;
        try {
            save = this.recommendFloorCoursesEntityMapper.deleteByPrimaryKey(recommendCourseGoodsId);
            result.setResult(save);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[RecommendFloorCoursesServiceModel][deleteByPrimaryKey]:query update occur exception", e);
        }
        return result;
    }

}
